#pragma once

#ifdef __cplusplus
extern "C"
{
#endif

#include <stdbool.h>
#include <stdint.h>

#define TIMERCLUSTER_FOREACH_ERR(X)            \
    X(0, SUCCESS, "Success")                   \
    X(-1, ERR_ARG, "Invalid argument")         \
    X(-2, ERR_MEM, "Memory allocation failed") \
    X(-3, ERR_AGAIN, "again operation")        \
    X(-16, ERR_OTHER, "Other error")

enum
{
#define X(code, name, msg) TIMERCLUSTER_RET_##name = code,
    TIMERCLUSTER_FOREACH_ERR(X)
#undef X
};

typedef uint32_t timerid_t;
typedef void (*timercallback_t)(timerid_t id, void *userdata);

typedef enum
{
    TIMER_TYPE_SINGLE = 1,
    TIMER_TYPE_CYCLE = 2
} timertype_e;

typedef struct _timercluster_t timercluster_t;

timercluster_t *timercluster_init(void);
void timercluster_destroy(timercluster_t *manager);

bool timercluster_timer_exist(timercluster_t *manager, timerid_t id);
bool timercluster_timer_add(timercluster_t *manager, timerid_t id, timertype_e type, uint32_t interval, timercallback_t cb, void *userdata);
bool timercluster_timer_del(timercluster_t *manager, timerid_t id);
bool timercluster_timer_reset(timercluster_t *manager, timerid_t id, uint32_t new_interval);
const char *timercluster_strerror(int err);

#ifdef __cplusplus
}
#endif
